# python
from .. import db

from flask_restful import Resource, fields, marshal_with

user_info_fields = {
    'user_id': fields.Integer,
    'age': fields.Integer,  # 年龄
    'weight': fields.Float,  # 体重cm
    'height': fields.Float,  # 身高cm
    'blood_pressure': fields.String,  # 血压 mmHg
    'heart_rate': fields.Integer,  # 心率 bpm
    'cholesterol': fields.Float,   # 胆固醇mg/dL
    'illnesses': fields.String,  # 疾病
    'create_time': fields.DateTime,  # 创建时间
}


class User(db.Model):
    user_id = db.Column(db.Integer, primary_key=True)
    age = db.Column(db.Integer)
    weight = db.Column(db.Float)
    height = db.Column(db.Float)
    blood_pressure = db.Column(db.String(120))
    heart_rate = db.Column(db.Integer)
    cholesterol = db.Column(db.Float)
    illnesses = db.Column(db.String(120))
    create_time = db.Column(db.DateTime, server_default=db.func.now())

    def to_dict(self):
        return {
            'user_id': self.user_id,
            'age': self.age,
            'weight': self.weight,
            'height': self.height,
            'blood_pressure': self.blood_pressure,
            'heart_rate': self.heart_rate,
            'cholesterol': self.cholesterol,
            'illnesses': self.illnesses,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S')
        }

    def __repr__(self):
        return f'<User {self.username}>'
